<?php
// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die( 'Restricted access' );


class ManagerModelConfig extends JModel {
	
	function __construct() {
		parent::__construct();
	}
	
	function count($where) {
		$query = "SELECT count(id) FROM #__configpim $where";
		$this->_db->setQuery($query);
		return $this->_db->loadResult();
	}
	
	function getData(&$total, &$dbrows , $order_by = 'id', $order_dir = 'DESC', $offset = 0, $limit = 30, $where=array()) {
		if(sizeof($where) > 0)
			$where = 'WHERE ' . implode(' AND ', $where);
		else 
			$where = '';
		
		if($limit !== 0)
			$limit	=	"LIMIT $offset, $limit";
		else 
			$limit	=	'';
			
		$query = "SELECT SQL_CALC_FOUND_ROWS * FROM #__configpim $where ORDER BY $order_by $order_dir $limit";
		$this->_db->setQuery($query);
		$dbrows = $this->_db->loadObjectList();
		
		$total = $this->count($where);
	}
	
	function getConfigByKey($key="") {
		 $query = "SELECT * FROM #__configpim WHERE pim_key='".$key."' ";
		
	     $this->_db->setQuery($query);
	     return $this->_db->loadObject();
	}
	
	function getConfig() {
		$query = " SELECT * FROM #__configpim" ;
		$this->_db->setQuery($query);
		$array_config = array();
		$dbrows = $this->_db->loadObjectList();
		
		foreach ($dbrows as $key=>$value) {
			$array_config[trim($value->pim_key)] = $value->pim_value;
		}
		
		return $array_config;  
	}
}